package com.xyx.bloodoxygenlib.impls;

import android.util.Log;

import com.xyx.bloodoxygenlib.interfaces.IBaseCallBack;
import com.xyx.bloodoxygenlib.interfaces.IReader;

import java.util.Vector;

public class Receive extends BaseThread {
    public static Vector<Byte> originalData = new Vector<>();
    private byte[] buffer = new byte[64];
    private IBaseCallBack callBack;
    private IReader is;

    public Receive(IReader is, IBaseCallBack callBack) {
        this.is = is;
        this.callBack = callBack;
    }

    @Override // com.creative.base.BaseThread
    public void Continue() {
        super.Continue();
        cleanData();
    }

    public void cleanData() {
        if (originalData != null) {
            originalData.clear();
        }
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public void run() {
        try {
            super.run();
            setName("receive thread");
            try {
                synchronized (this) {
                    while (!this.stop && this.is != null) {
                        try {
                            if (this.pause) {
                                wait();
                            }
                            if (this.is.available() > 0) {
                                int len = this.is.read(this.buffer);
                                for (int i = 0; i < len; i++) {
                                    originalData.add(Byte.valueOf(this.buffer[i]));
                                }
                            }
                        } catch (Throwable th) {
                            throw th;
                        }
                    }
                }
                this.callBack.OnConnectLose();
                Log.e("Receive", "Receive finally cleanData");
                synchronized (this) {
                    try {
                        cleanData();
                    } catch (Throwable th2) {
                        throw th2;
                    }
                }
            } catch (Exception e) {
                Log.e("Receive", "Receive Exception:" + e.getMessage());
                e.printStackTrace();
                this.callBack.OnConnectLose();
                Log.e("Receive", "Receive finally cleanData");
                synchronized (this) {
                    try {
                        cleanData();
                    } catch (Throwable th3) {
                        throw th3;
                    }
                }
            }
        } catch (Throwable th4) {
            this.callBack.OnConnectLose();
            Log.e("Receive", "Receive finally cleanData");
            synchronized (this) {
                try {
                    cleanData();
                    throw th4;
                } catch (Throwable th5) {
                    throw th5;
                }
            }
        }
    }
}
